struct ListNode* removeElements(struct ListNode* head, int val) {

	struct ListNode* cur = head;
	struct ListNode* prev = head;
	while (cur)
	{
		if (cur->val== val)
		{
			if (cur == prev)
			{
				prev = prev->next;
				head = prev;
				free(cur);
				cur = prev;
			}
			else
			{
				while (prev->next != cur)
				{
					prev = prev->next;
				}
				prev->next = cur->next;
				free(cur);
				cur = prev->next;
			}
		}
		else
		{
			cur = cur->next;
		}
	}
	return head;
}